package com.example.bookstore.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.bookstore.common.Result;
import com.example.bookstore.entity.Admin;
import com.example.bookstore.entity.User;
import com.example.bookstore.mapper.AdminMapper;
import com.example.bookstore.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    @Autowired
    AdminMapper adminMapper;

    @Override
    public Admin getAdmin(long id) {
        Admin admin = adminMapper.selectById(id);
        return admin;
    }

    @Override
    public Admin login(String username, String password) {
        LambdaQueryWrapper<Admin> lqw=new LambdaQueryWrapper<>();
        lqw.eq(Admin::getAdminName,username);
        Admin admin = adminMapper.selectOne(lqw);
        if (admin==null){
            return null;
        }
        if (admin.getAdminPassword().equals(password)){
            return admin;
        }
        return null;
    }
}
